package com.symria.server.bo.common;

import java.util.Date;

import com.symria.framework.page.Page;
import com.symria.server.dao.common.FinanceDao;
import com.symria.server.po.AdAppReport;
import com.symria.server.po.AppDateReport;
import com.symria.server.po.AppInfo;
import com.symria.server.po.PayInfo;
import com.symria.server.po.UserAccount;
import com.symria.server.po.UserInfo;

public class FinanceService extends CommonService {

	private FinanceDao financeDao;
	
	public void searchAppDateReport(AppDateReport aar,Date beginDate,Date endDate,Page page){
		financeDao.searchAppDateReport(aar, beginDate, endDate, page);
	}
	public void searchUserAccount(UserInfo user,Date beginDate,Date endDate,Page page){
		financeDao.searchUserAccount(user, beginDate, endDate, page);
	}
    public void searchPayInfo(UserInfo user,Date beginDate,Date endDate,String state,Page page){
    	financeDao.searchPayInfo(user, beginDate, endDate, state,page);
	}
	public void updateAppDateReport(Integer[] ids){
		for(Integer id:ids){
			AppDateReport aar = getObject(id, AppDateReport.class);
			if(aar!=null&&"no_pay".equals(aar.getState())){
				aar.setFactMoney(aar.getPayMoney());
				aar.setState("pay");
				updateObject(aar);
				AppInfo app = getObject(aar.getAppId(), AppInfo.class);
                if(app!=null){
                	UserAccount ua = getObject(app.getUserId(), UserAccount.class);
                	if(ua!=null){
                		Double money=ua.getPayMoney()==null?0d:ua.getPayMoney();
                		ua.setPayMoney(money+aar.getPayMoney());
                		updateObject(ua);
                	}
                }
			}
		}
	}
	public void updatePayInfo(Integer[] ids){
		for(Integer id:ids){
			PayInfo pay = getObject(id, PayInfo.class);
			if(pay!=null&&"no_pay".equals(pay.getState())){
				pay.setState("pay");
				updateObject(pay);
			}
		}
	}
	
	
	
	public FinanceDao getFinanceDao() {
		return financeDao;
	}
	public void setFinanceDao(FinanceDao financeDao) {
		this.financeDao = financeDao;
	}
	
	
	
}
